import { PollEntity } from '@/api/manager/poll/interface'
import { VmpEntity } from './interface'

export function transVmpDTO(data: VmpEntity, plan?: 'plan') {
	let isPlan = plan === 'plan'
	return {
		id: data.id,
		name: data.name,
		layout: data.layout,
		mode: data.mode,
		except_self: data.except_self,
		voice_hint: data.voice_hint,
		broadcast: data.broadcast,
		show_mt_name: data.show_mt_name,
		mt_name_style: {
			font_color: data.mt_name_style?.font_color,
			font_size: data.mt_name_style?.font_size,
			position: data.mt_name_style?.position,
		},
		poll: data.poll ? transPoll(data.poll, plan) : undefined,
		members: data.members
			? data.members.map((item) => ({
					chn_idx: item.chn_idx,
					member_type: item.member_type,
					name: item.name,
					account: item.account,
					account_type: item.account_type,
					mt_id: item.mt_id ? item.mt_id : item.mt_key,
					conf_e164: isPlan
						? item.mt_key && `${item.mt_key}`.includes('_')
							? item.conf_e164
							: ''
						: item.conf_e164,
					poll: item.poll ? transPoll(item.poll, plan) : undefined,
					mt_key: item.mt_key || '',
					e164: item.e164 || '',
			  }))
			: undefined,
	}
}
export function transPoll(data: PollEntity, plan?: 'plan') {
	let isPlan = plan === 'plan'
	return {
		name: data.name,
		keep_time: data.keep_time,
		num: data.num,
		members: data.members.map((item) =>
			Object.assign(
				{ ...item },
				{
					account: item.account,
					account_type: item.account_type,
					name: item.name,
					mt_id: item.mt_id ? item.mt_id : item.mt_key,
					conf_e164: isPlan
						? item.mt_key && `${item.mt_key}`.includes('_')
							? item.conf_e164
							: ''
						: item.conf_e164,
				}
			)
		),
	}
}
